<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    canvas {
      border: 1px solid #ccc;
    }
  </style>
</head>

<body>
  <canvas width="600" height="400"></canvas>

</body>
<script>
  let canvas = document.querySelector("canvas")
  let ctx = canvas.getContext("2d")

  //绘制描边矩形
  // ctx.strokeStyle="red"
  // ctx.strokeRect(0,0,300,200)

  //绘制实心矩形
  // ctx.fillStyle="red"
  // ctx.fillRect(0,0,200,200)

  // 擦除矩形
  // ctx.clearRect(0,0,100,100)
  // ctx.clearRect(100,0,100,100)
  // ctx.clearRect(0,0,200,200)

  // ctx.strokeStyle="red"
  // ctx.strokeRect(250,0,100,100)

  //矩形垂直下落
  ctx.fillStyle="red";
  let y=0;
  setInterval(()=>{
    ctx.clearRect(250,y,100,100)
    y++
    ctx.fillRect(250,y,100,100)
  },10)
  




</script>

</html>